package com.cljz.makepassenger.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.GetTypeListBean;
import com.cljz.makepassenger.ui.holder.NearbyTagsHolder;

import java.util.List;

/**
 * Created by apple on 2017/4/26.
 */


public class NearbyTagsAdapter extends RecyclerView.Adapter<NearbyTagsHolder> {
    private Context context;
    private List<GetTypeListBean.DataBean> tagsList;
    private OnItemClickListener mOnItemClickListener;


    public List<GetTypeListBean.DataBean> getTagsList() {
        return tagsList;
    }

    public void setTagsList(List<GetTypeListBean.DataBean> tagsList) {
        this.tagsList = tagsList;
        notifyDataSetChanged();
    }


    public NearbyTagsAdapter(Context context, List<GetTypeListBean.DataBean> typeList) {
        this.context = context;
        this.tagsList = typeList;
    }

    @Override
    public NearbyTagsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new NearbyTagsHolder(View.inflate(context, R.layout.item_nearby_tags, null));
    }

    @Override
    public void onBindViewHolder(NearbyTagsHolder holder, final int position) {
        holder.setData(tagsList, position);
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onTypeClick(tagsList, position);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    mOnItemClickListener.onLongClick(tagsList, position);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return tagsList == null ? 0 : tagsList.size();
    }

    public interface OnItemClickListener {
        void onTypeClick(List<GetTypeListBean.DataBean> typeList, int position);

        void onLongClick(List<GetTypeListBean.DataBean> typeList, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }


}
